package com.zggk.lzz.bridgetmx;


import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zggk.lzz.R;
import com.zggk.lzz.adapter.LGRecycleViewAdapter;
import com.zggk.lzz.mvp.MVPBaseActivity;
import com.zggk.lzz.sjcx.SjcxBean;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class BridgeTMxActivity extends MVPBaseActivity<BridgeTMxContract.View, BridgeTMxPresenter> implements BridgeTMxContract.View {

    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.cancle_button)
    TextView cancleButton;
    @Bind(R.id.barChart)
    BarChart barChart;
    @Bind(R.id.disease_new_parent_layout)
    LinearLayout diseaseNewParentLayout;
    @Bind(R.id.lay_xm)
    LinearLayout layXm;
    @Bind(R.id.recycle_view)
    RecyclerView recycleView;
    private LGRecycleViewAdapter<SjcxBean.DataBean.RecordsBean> adapter;

    @Override
    public void onRequestError(String msg) {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_bridge_t_mx;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        initBarChart(barChart);
        initAdapter();
        setTitleText("桥梁统计");
        goBack();
    }

    private void initAdapter() {
//        LinearLayoutManager manager = new LinearLayoutManager(getContext());
//        manager.setOrientation(LinearLayoutManager.VERTICAL);
//        recycleView.setLayoutManager(manager);
//        adapter = new LGRecycleViewAdapter<SjcxBean.DataBean.RecordsBean>(ListDatas) {
//            @Override
//            public int getLayoutId(int viewType) {
//                return R.layout.item_bridge_t_mx;
//            }
//
//            @Override
//            public void convert(LGViewHolder holder, SjcxBean.DataBean.RecordsBean zCDBean, int position) {
//                LinearLayout layXm=(LinearLayout)holder.getView(R.id.lay_xm);
//                if (position % 2 == 0) {
//                    layXm.setBackgroundDrawable(getResources().getDrawable(R.color.bridge_t_mx_color1));
//                } else {
//                    layXm.setBackgroundDrawable(getResources().getDrawable(R.color.bridge_t_mx_color2));
//                }
//            }
//        };
//        recycleView.setAdapter(adapter);
    }

    private void initBarChart(BarChart barChart) {
        List<BarEntry> barEntryList = new ArrayList<>();

        barEntryList.add(new BarEntry(0, 89.2f));
        barEntryList.add(new BarEntry(1, 86.3f));
        barEntryList.add(new BarEntry(2, 92.9f));
        barEntryList.add(new BarEntry(3, 89.4f));
        barEntryList.add(new BarEntry(4, 91.5f));
        barEntryList.add(new BarEntry(5, 91.5f));

        BarDataSet barDataSet = new BarDataSet(barEntryList, "");
//        设置颜色(7个柱子，7个颜色)
        List<Integer> colors = new ArrayList<Integer>();
        colors.add(getResources().getColor(R.color.seven_color));
        colors.add(getResources().getColor(R.color.seven_color));
        colors.add(getResources().getColor(R.color.two_color));
        colors.add(getResources().getColor(R.color.seven_color));
        colors.add(getResources().getColor(R.color.two_color));
        colors.add(getResources().getColor(R.color.two_color));
        barDataSet.setColors(colors);


        BarData barData = new BarData(barDataSet);
        barData.setBarWidth(0.5f); // 设置柱子的宽度
        barChart.setData(barData);

        barData.setValueTextSize(10);

//        去除description
        barChart.getDescription().setEnabled(false);
//        去除 Legend
        barChart.getLegend().setEnabled(false);
//        去除对图标的触摸操作，如果没有去除，可以通过触摸对折线图进行
//        放大，缩小等操作。
        barChart.setTouchEnabled(false);


//        X轴处理
        XAxis barXaxis = barChart.getXAxis();
//        设置x轴的表格线不显示
        barXaxis.setDrawGridLines(false);
//        设置X轴的位置为正下方
        barXaxis.setPosition(XAxis.XAxisPosition.BOTTOM);
//        自定义X轴上的刻度显示
        final String label[] = {"PQI", "PCI", "RQI", "RDI", "SRI", "PSSI"};
        barXaxis.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return label[(int) value];
            }
        });

//        Y轴处理
        YAxis barYaxis = barChart.getAxis(YAxis.AxisDependency.LEFT);
        barYaxis.setDrawGridLines(false); // 这里设置左侧y轴显示轴线
        barYaxis.setAxisMinimum(0); //设置y轴从0刻度开始
        barYaxis.setAxisMaximum(100); //设置y轴从0刻度开始
        barYaxis.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return (int) value + "";
            }
        });
//        隐藏右侧Y轴
        barChart.getAxisRight().setEnabled(false);
    }


}
